﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;
using AdventureWorks.BusinessObjects;

namespace AdventureWorks.Parameters
{
    public class CurrentProductParameter : Catalyst.Web.DynamicData.DynamicExpressionParameterBase
    {
        public override System.Linq.Expressions.LambdaExpression GetLambdaExpression(Type itType)
        {
            if (itType != typeof(Product))
                throw new ArgumentException("CurrentProductParameter only works with Product type");

            Expression<Func<Product, bool>> lambda = x => (x.SellStartDate <= DateTime.Now)
                                                            && (x.SellEndDate == null || x.SellEndDate >= DateTime.Now);
            return lambda;
        }
    }
}
